package com.yunyao.dao;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;

/**
 * @author xingjishuai
 */
public class MyBatisPlusGenerator {

    public static void main(String[] args) {
        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig.Builder(
                "jdbc:mysql://47.94.154.22:3306/prod_zj?zeroDateTimeBehavior=convertToNull&&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8",
                "root",
                "Yykj@202406")
                .dbQuery(new MySqlQuery())
                .schema("prod_zj")
                .typeConvert(new MySqlTypeConvert())
                .keyWordsHandler(new MySqlKeyWordsHandler())
                .build();

        // 全局配置
        GlobalConfig gc = new GlobalConfig.Builder()
                .outputDir(System.getProperty("user.dir")+"/yunyao-dao/src/main/java")
                .author("xingjishuai")
                .disableOpenDir()
                .dateType(DateType.ONLY_DATE)
                .commentDate("yyyy-MM-dd")
                .build();

        // 包配置
        PackageConfig pc = new PackageConfig.Builder()
                .parent("com.yunyao.dao")
                .entity("model")
                .mapper("mapper")
                .service("service")
                .serviceImpl("service.impl")
                .controller("controller")
                .xml("mapper.xml")
                .build();

        // 策略配置
        StrategyConfig strategy = new StrategyConfig.Builder()
                //指定表 生成代码 .addInclude("mdm_data_receive_record")
                .entityBuilder()
                .disableSerialVersionUID()
                .naming(NamingStrategy.underline_to_camel)
                .columnNaming(NamingStrategy.underline_to_camel)
                .enableLombok()
                .build();

        // 执行生成
        AutoGenerator ag = new AutoGenerator(dsc);
        ag.global(gc);
        ag.packageInfo(pc);
        ag.strategy(strategy);
        ag.execute();
    }
}
